#!/bin/bash
rlscfg="../APP/ReleaseCfg.h"		#specify the target C header file

echo "Hello, Today is" `date +"%Y.%m.%d"`

echo "svn version:" `svn --version --quiet`			#show version only, command execution result saved in $?
if [ ! $? ]
then
	echo "svn command line support disabled, Pls install this feature!"
	exit 2
fi

if [ ! -e $rlscfg ]
then
	echo "Fatal: $rlscfg Not Found, Pls specify the right path!"
	exit 2	#abnormal exit flag
fi

rev=$(svn info | grep -E 'Revision:' | awk '/Revision:/{print $2}')			#"Revision: 123"
oldrev=$(grep -E "SVN_REVISION[[:space:]]+[0-9]+" $rlscfg | awk '/[0-9]+/{print $3}')		#"#define SVN_REVISION       123"
echo "rev $rev, oldrev $oldrev"

if [ -z $rev ]
then
	echo "Revision number failed to retrieve!"
elif [ "$oldrev" = "$rev" ]		#comparison of strings
then
	echo "Revision not changed, Jump over..."
else
	echo "Modifying new revision number..."
	#write revision number to SVN_REVISION
	sed -i "s/\(SVN_REVISION[[:space:]]\{1,\}\)[0-9]\{1,\}/\1$rev/" $rlscfg
fi

echo "Preprocessing done!"
exit